﻿namespace Sharemarker.Service
{
    using System.Data.Linq;

    using Autofac;

    using Sharemarker.Common;
    using Sharemarker.Common.DataAccess;
    using Sharemarker.DataAccess;

    using log4net;

    /// <summary>
    /// 
    /// </summary>
    public class DependencyServiceRegister
    {
        #region Static Fields

        /// <summary>
        /// 
        /// </summary>
        private static readonly ILog Logger = LogManager.GetLogger(typeof(DependencyServiceRegister));

        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// Registers the specified container builder.
        /// </summary>
        /// <param name="containerBuilder">The container builder.</param>
        /// <param name="config">The config.</param>
        public static void Register(ContainerBuilder containerBuilder, ServiceConfig config)
        {
            containerBuilder.Register<IUnitOfWork<DataContext>>(
                context =>
                new DataContextUnitOfWork(() => new ForexDataFeedDataContext(config.ForexFeedDatabaseConnectionString)))
                .SingleInstance();

            DependencyCommonRegister.Register(containerBuilder);
            DependencyDataAcessRegister.Register(containerBuilder);
            DependencyDataAcessRegister.Register(containerBuilder, config.SecurityCheckConnectionString);
        }

        #endregion
    }
}